<template>
	<view>
		<stop isBack>
			<view slot="content">故障维修确认</view>
		</stop>
		<view class="lh2 bcf pad2 mart3">
			<sentity label="故障原因" model="MachineFixCategory" placeholder="请选择" v-model="en.category"></sentity>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sentity label="维修类别" model="MachineFixReason" placeholder="请选择" v-model="en.reason"></sentity>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<sentity label="维修等级" model="MachineFixLevel" placeholder="请选择" v-model="en.level"></sentity>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<stext label="停机时间" placeholder="记录停机时间（分钟）" v-model="en.stopTime" suffix="分钟"></stext>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<stextarea label="故障描述" placeholder="简单描述故障情况" v-model="en.tips"></stextarea>
		</view>
		<view class="lh2 bcf pad2 mart3">
			<spics label="附件" placeholder="维修完成状态" v-model="en.pics"></spics>
		</view>
		<view class="lh2 bcf pad2 bdtso pos-f b0 l0 r0">
			<view class="tac pad2 line-green round cu-btn lg w100 mart5" @tap="submit">
				<view>提交</view>
				<ripple></ripple>
			</view>
		</view>
		<!-- <loading :loading="myIsLoading"></loading> -->
	</view>
</template>

<script>
	export default {
		components:{},
		data() {
			return {
				id:"",
				en:{
					id:'',
					category:'',
					level:'',
					reason:'',
					stopTime:'0',
					tips:'',
					pics:[],
				}
			}
		},
		methods: {
			submit(){
				this.log(this.en)
				//检查数据
				// machine:'',
				// category:'',
				// level:'',
				// reason:'',
				// stopTime:false,
				// tips:'',
				// pics:[],
				if(this.isnull(this.en.reason)){this.$com.showToast('请选择故障原因');return;}
				if(this.isnull(this.en.category)){this.$com.showToast('请选择维修类别');return;}
				if(this.isnull(this.en.level)){this.$com.showToast('请选择维修等级');return;}
				if(this.isnull(this.en.tips)){this.$com.showToast('请简单说明故障情况');return;}
				this.$api.patch("/api/machineFixOrders/" + this.id,this.en,(res)=>{
					this.log(res)
					if(res.s == 1){
						this.goback()
					}
				})
			}
		},
		onLoad(option) {
			this.clearLoading()
			this.id = option.id
			this.en.id = option.id
			if(this.isbool(this.id)){
				this.$api.get('/api/machineFixOrders/'+this.id,{},res=>{
					this.en.reason = res.d.reason
					this.en.category = res.d.category
					this.en.level = res.d.level
					this.en.stopTime = res.d.stopTime
					//再次获取图片和描述
					let orderId = this.$com.iriId(res.d.breakOrder)
					this.$api.res("machine_breaks",orderId,machine_breaks=>{
						this.en.tips = machine_breaks.tips
						this.en.pics = this.isbool(machine_breaks.pic)?machine_breaks.pic:[]
					})
				})
			}
			
		}
	}
</script>

<style>

</style>
